<template>
	<view class="mainpadding">
		<view class="ffffff radius mainpadding flexbetween">
			<view class="ershiba zhonghei">真实姓名</view>
			<input class="textright" placeholder="请输入真实姓名" type="text" v-model="name"/>
		</view>
		<view class="ffffff radius mainpadding flexbetween margin_top">
			<view class="ershiba zhonghei">身份证号</view>
			<input class="textright" placeholder="请输入身份证号" type="text" v-model="idcard"/>
		</view>
		<view class="flexbetween margin_top">
			<image class="sfzfm" src="../static/images/system/sfzzm.png" @click="upflag=0;uploadImg()" v-if="!idcard_zimage_text" mode=""></image>
			<image class="sfzfm" :src="idcard_zimage_text" @click="upflag=0;uploadImg()" v-if="idcard_zimage_text" mode=""></image>
			<image class="sfzfm" src="../static/images/system/sfzfm.png" @click="upflag=1;uploadImg()" v-if="!idcard_fimage_text" mode=""></image>
			<image class="sfzfm" :src="idcard_fimage_text" @click="upflag=1;uploadImg()" v-if="idcard_fimage_text" mode=""></image>
		</view>
		<view class="gudingdb mainpadding" @click="smrz">
			<view class="bigbtn">提交审核</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				name:"",
				idcard:"",
				idcard_zimage:"",
				idcard_zimage_text:"",
				idcard_fimage:"",
				idcard_fimage_text:"",
				upflag:0,//0正面，1反面
			}
		},
		methods: {
			smrz(){
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				if (this.real_name == "") {
					uni.hideLoading()
					httpRequest.toast("请输入真实姓名")
					return
				}
				if (this.id_card == "") {
					uni.hideLoading()
					httpRequest.toast("请输入身份证号")
					return
				}
				if (this.idcard_zimage == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证头面像")
					return
				}
				if (this.idcard_fimage == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证国徽面")
					return
				}
				httpRequest.request('/api/user/smrz', 'POST', {
					// 传参
					name: this.name, //持卡人
					idcard: this.idcard, //银行卡号
					idcard_zimage: this.idcard_zimage, //开户行
					idcard_fimage: this.idcard_fimage, //开户行地址
				}, false, false, true).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			uploadImg() {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									console.log(res[i])
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					if(this.upflag==0){
						this.idcard_zimage = res.url;
						this.idcard_zimage_text = image_item;
					}else{
						this.idcard_fimage = res.url;
						this.idcard_fimage_text = image_item;
					}
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
.sfzfm{
	width: 336rpx;
	height:291rpx ;
}
</style>
